package com.twu.biblioteca;

public class bookReservation {
    private bookCatalogue currentCollection;
    private displayStock displayObject;

    public bookReservation(bookCatalogue collection){
        currentCollection = new bookCatalogue();
        currentCollection = collection;
        displayObject = new displayStock(currentCollection);
    }

    // gets user choice from Menu
    public void getBookFromUser(){
        displayObject.display();
        System.out.print("Enter book ID for reserving appropriate book");
        checkUserInput checkInput = new checkUserInput(System.in);
        Integer bookIDToReserve = checkInput.takeUserInput();
        reserveABook(displayObject.idIndex.get(bookIDToReserve));
    }

    //Scans current book store , finds available copies once book is located
    public void reserveABook(Integer index){
        int iterator;
        Book bookToReserve;
        bookToReserve = currentCollection.allBooks().get(index);

        if(bookToReserve.availibleCopies()==0) System.out.print("Sorry we don't have that book yet.");
        else{
            for (iterator = 0; iterator < bookToReserve.bookCopies.size(); iterator++) {
                if(!bookToReserve.bookCopies.get(iterator).isReserved()){
                    System.out.print("\nThank You! Enjoy the book.");
                    bookToReserve.bookCopies.get(iterator).setReservationStatus(true);
                    bookToReserve.reserveCopyCount++;
                    break;
                }
            }

        }
    }
}
